﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Turnstile: Test/TurnstileTest/TurnstileTest.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Turnstile: Test/TurnstileTest/TurnstileTest.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Test/TurnstileTest/TurnstileTest.cs</div>  </div>
</div>
<div class="contents">
<a href="_turnstile_test_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// This class is a basic framework to test a state machine with NUnit and RhinoMock.</span>
<a name="l00004"></a>00004 <span class="comment">//</span>
<a name="l00005"></a>00005 
<a name="l00006"></a><a class="code" href="namespace_state_forge_1_1_examples_1_1_turnstile.html">00006</a> <span class="keyword">namespace </span>StateForge.Examples.<a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile.html">Turnstile</a>
<a name="l00007"></a>00007 {
<a name="l00008"></a>00008     <span class="keyword">using</span> System;
<a name="l00009"></a>00009     <span class="keyword">using</span> NUnit.Framework;
<a name="l00010"></a>00010     <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00011"></a>00011     <span class="keyword">using</span> Rhino.Mocks;
<a name="l00012"></a>00012 
<a name="l00013"></a>00013     [TestFixture]
<a name="l00014"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html">00014</a>     <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html">TurnstileTest</a>
<a name="l00015"></a>00015     {
<a name="l00016"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a2ad287791b86f686a24cf636a7c563d4">00016</a>         <span class="keyword">private</span> TurnstileContext <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a2ad287791b86f686a24cf636a7c563d4">context</a>;
<a name="l00017"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a487011eafe854e7387ce44f00a4cd862">00017</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_barrier.html">Barrier</a> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a487011eafe854e7387ce44f00a4cd862">barrier</a>;
<a name="l00018"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a1d3174ea0025320c4d3662462f8e9d64">00018</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_alarm.html">Alarm</a> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a1d3174ea0025320c4d3662462f8e9d64">alarm</a>;
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a76acfe34ae8297ed9477d291dae6d3d4">00019</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_coin_machine.html">CoinMachine</a> <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a76acfe34ae8297ed9477d291dae6d3d4">coinMachine</a>;
<a name="l00020"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a69917f4f9a3b4266ae04f1b55a91dabb">00020</a>         <span class="keyword">private</span> MockRepository <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a69917f4f9a3b4266ae04f1b55a91dabb">repository</a>;
<a name="l00021"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a4a3d6ad433b41838b38f321dfa71e8cc">00021</a>         <span class="keyword">private</span> IObserver <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a4a3d6ad433b41838b38f321dfa71e8cc">observer</a>;
<a name="l00022"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a603058590e4c593d65abbcf974c426a7">00022</a>         <span class="keyword">private</span> <span class="keyword">static</span> String contextName = <span class="stringliteral">&quot;TurnstileContext&quot;</span>;
<a name="l00023"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a76f136010fe9303519b1ebca5427fbaf">00023</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> current, next, <a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a76f136010fe9303519b1ebca5427fbaf">transition</a>;
<a name="l00024"></a>00024 
<a name="l00025"></a>00025         [SetUp]
<a name="l00026"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a6d86f0c928aeff41d69445e79cec664a">00026</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Setup()
<a name="l00027"></a>00027         {
<a name="l00028"></a>00028             repository = <span class="keyword">new</span> MockRepository();
<a name="l00029"></a>00029             this.barrier = repository.StrictMock&lt;<a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_barrier.html">Barrier</a>&gt;();
<a name="l00030"></a>00030             this.alarm = repository.StrictMock&lt;<a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_alarm.html">Alarm</a>&gt;();
<a name="l00031"></a>00031             this.coinMachine = repository.StrictMock&lt;<a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_coin_machine.html">CoinMachine</a>&gt;();
<a name="l00032"></a>00032             observer = repository.StrictMock&lt;IObserver&gt;();
<a name="l00033"></a>00033             this.context = <span class="keyword">new</span> TurnstileContext(this.barrier, this.alarm, this.coinMachine);
<a name="l00034"></a>00034             this.context.Observer = observer;
<a name="l00035"></a>00035         }
<a name="l00036"></a>00036 
<a name="l00037"></a>00037         [TearDown]
<a name="l00038"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#afc86e7add7dba0da40938cd0b04d83c1">00038</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> TearDown()
<a name="l00039"></a>00039         {
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042 
<a name="l00043"></a>00043         [Test]
<a name="l00044"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a39a0b87977ba6bb75cc41326e0c526cb">00044</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Coin()
<a name="l00045"></a>00045         {
<a name="l00046"></a>00046             <span class="keyword">using</span> (repository.Record())
<a name="l00047"></a>00047             {
<a name="l00048"></a>00048                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00049"></a>00049                 {
<a name="l00050"></a>00050                     <span class="comment">// this.context.EnterInitialState();</span>
<a name="l00051"></a>00051                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Root&quot;</span>));
<a name="l00052"></a>00052                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Locked&quot;</span>));
<a name="l00053"></a>00053                     Expect.Call(() =&gt; this.barrier.DoLock());
<a name="l00054"></a>00054 
<a name="l00055"></a>00055                     <span class="comment">// this.context.Coin();</span>
<a name="l00056"></a>00056                     current = <span class="stringliteral">&quot;Locked&quot;</span>; next = <span class="stringliteral">&quot;Unlocked&quot;</span>; transition = <span class="stringliteral">&quot;Coin&quot;</span>;
<a name="l00057"></a>00057                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00058"></a>00058                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00059"></a>00059                     Expect.Call(() =&gt; this.coinMachine.DoAccept());
<a name="l00060"></a>00060                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00061"></a>00061                     Expect.Call(() =&gt; this.barrier.DoUnlock());
<a name="l00062"></a>00062                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00063"></a>00063                 }
<a name="l00064"></a>00064             }
<a name="l00065"></a>00065 
<a name="l00066"></a>00066             <span class="keyword">using</span> (repository.Playback())
<a name="l00067"></a>00067             {
<a name="l00068"></a>00068                 this.context.EnterInitialState();
<a name="l00069"></a>00069                 this.context.Coin();
<a name="l00070"></a>00070             }
<a name="l00071"></a>00071         }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073         [Test]
<a name="l00074"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#ac7c9d912ec28198d5c8808e1a2b7725c">00074</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Pass()
<a name="l00075"></a>00075         {
<a name="l00076"></a>00076             <span class="keyword">using</span> (repository.Record())
<a name="l00077"></a>00077             {
<a name="l00078"></a>00078                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00079"></a>00079                 {
<a name="l00080"></a>00080                     current = <span class="stringliteral">&quot;Locked&quot;</span>; next = <span class="stringliteral">&quot;Locked&quot;</span>; transition = <span class="stringliteral">&quot;Pass&quot;</span>;
<a name="l00081"></a>00081                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, next, next, transition));
<a name="l00082"></a>00082                     Expect.Call(() =&gt; this.alarm.DoAlertStaff());
<a name="l00083"></a>00083                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, next, next, transition));
<a name="l00084"></a>00084                 }
<a name="l00085"></a>00085             }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087             <span class="keyword">using</span> (repository.Playback())
<a name="l00088"></a>00088             {
<a name="l00089"></a>00089                 this.context.Pass();
<a name="l00090"></a>00090             }
<a name="l00091"></a>00091         }
<a name="l00092"></a>00092         [Test]
<a name="l00093"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#ad8b096f5e757df6c099685d72fd31510">00093</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> CoinPass()
<a name="l00094"></a>00094         {
<a name="l00095"></a>00095             <span class="keyword">using</span> (repository.Record())
<a name="l00096"></a>00096             {
<a name="l00097"></a>00097                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00098"></a>00098                 {
<a name="l00099"></a>00099                     <span class="comment">//this.context.Coin();</span>
<a name="l00100"></a>00100                     current = <span class="stringliteral">&quot;Locked&quot;</span>; next = <span class="stringliteral">&quot;Unlocked&quot;</span>; transition = <span class="stringliteral">&quot;Coin&quot;</span>;
<a name="l00101"></a>00101                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00102"></a>00102                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00103"></a>00103                     Expect.Call(() =&gt; this.coinMachine.DoAccept());
<a name="l00104"></a>00104                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00105"></a>00105                     Expect.Call(() =&gt; this.barrier.DoUnlock());
<a name="l00106"></a>00106                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00107"></a>00107 
<a name="l00108"></a>00108                     <span class="comment">//this.context.Pass();</span>
<a name="l00109"></a>00109                     current = <span class="stringliteral">&quot;Unlocked&quot;</span>; next = <span class="stringliteral">&quot;Locked&quot;</span>; transition = <span class="stringliteral">&quot;Pass&quot;</span>;
<a name="l00110"></a>00110                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00111"></a>00111                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00112"></a>00112                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, <span class="stringliteral">&quot;Locked&quot;</span>));
<a name="l00113"></a>00113                     Expect.Call(() =&gt; this.barrier.DoLock());
<a name="l00114"></a>00114                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00115"></a>00115                 }
<a name="l00116"></a>00116             }
<a name="l00117"></a>00117 
<a name="l00118"></a>00118             <span class="keyword">using</span> (repository.Playback())
<a name="l00119"></a>00119             {
<a name="l00120"></a>00120                 this.context.Coin();
<a name="l00121"></a>00121                 this.context.Pass();
<a name="l00122"></a>00122             }
<a name="l00123"></a>00123         }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125         [Test]
<a name="l00126"></a><a class="code" href="class_state_forge_1_1_examples_1_1_turnstile_1_1_turnstile_test.html#a3279663acc066ddcd8df1aef1372395d">00126</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> CoinCoin()
<a name="l00127"></a>00127         {
<a name="l00128"></a>00128             <span class="keyword">using</span> (repository.Record())
<a name="l00129"></a>00129             {
<a name="l00130"></a>00130                 <span class="keyword">using</span> (repository.Ordered())
<a name="l00131"></a>00131                 {
<a name="l00132"></a>00132                     <span class="comment">// this.context.Coin();</span>
<a name="l00133"></a>00133                     current = <span class="stringliteral">&quot;Locked&quot;</span>; next = <span class="stringliteral">&quot;Unlocked&quot;</span>; transition = <span class="stringliteral">&quot;Coin&quot;</span>;
<a name="l00134"></a>00134                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00135"></a>00135                     Expect.Call(() =&gt; this.observer.OnExit(contextName, current));
<a name="l00136"></a>00136                     Expect.Call(() =&gt; this.coinMachine.DoAccept());
<a name="l00137"></a>00137                     Expect.Call(() =&gt; this.observer.OnEntry(contextName, next));
<a name="l00138"></a>00138                     Expect.Call(() =&gt; this.barrier.DoUnlock());
<a name="l00139"></a>00139                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00140"></a>00140 
<a name="l00141"></a>00141                     <span class="comment">// this.context.Coin();</span>
<a name="l00142"></a>00142                     current = <span class="stringliteral">&quot;Unlocked&quot;</span>; next = <span class="stringliteral">&quot;Unlocked&quot;</span>; transition = <span class="stringliteral">&quot;Coin&quot;</span>;
<a name="l00143"></a>00143                     Expect.Call(() =&gt; this.observer.OnTransitionBegin(contextName, current, next, transition));
<a name="l00144"></a>00144                     Expect.Call(() =&gt; this.coinMachine.DoReject());
<a name="l00145"></a>00145                     Expect.Call(() =&gt; this.alarm.DoRing());
<a name="l00146"></a>00146                     Expect.Call(() =&gt; this.observer.OnTransitionEnd(contextName, current, next, transition));
<a name="l00147"></a>00147                 }
<a name="l00148"></a>00148             }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150             <span class="keyword">using</span> (repository.Playback())
<a name="l00151"></a>00151             {
<a name="l00152"></a>00152                 this.context.Coin();
<a name="l00153"></a>00153                 this.context.Coin();
<a name="l00154"></a>00154             }
<a name="l00155"></a>00155         }
<a name="l00156"></a>00156     }
<a name="l00157"></a>00157 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
